﻿@model String
@{
    var o = this; // instancia um objeto da view
    var model = o.ViewData.ModelMetadata.ContainerType; // pega o tipo do objeto (modelo)
    var name = o.ViewData.ModelMetadata.PropertyName; // pega o nome do atributo (nome do campo)
    var prop = model.GetProperty(name); // pega a propriedade 
    var max = ((System.ComponentModel.DataAnnotations.StringLengthAttribute)prop
        .GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.StringLengthAttribute), false)
        .FirstOrDefault()).MaximumLength; // pega o maxlength da propriedade
    var required = o.ViewData.ModelMetadata.IsRequired;
    var isCliente = User.IsInRole("Cliente");
    int width;
    if (max <= 10)
    {
        width = 80;
    }
    else if (max > 10 && max <= 15)
    {
        width = 125;
    }
    else if (max > 15 && max < 100)
    {
        width = 200;
    }
    else if (max > 100 && max < 150)
    {
        width = 300;
    }
    else
    {
        width = 400;
    }
}
@if (isCliente)
{
    if (max > 400)
    {
    @Html.TextArea("", Model, new { maxlength = max, style = "width: " + (width) + "px; height: 60px;", @class = "textarea readonly", @readonly = "readonly" })
    }
    else
    {
    @Html.TextBox("", Model, new { maxlength = max, style = "width: " + width + "px;", @class = "readonly",  @readonly = "readonly" })     
    }
}
else
{
    if (max > 400)
    {
    @Html.TextArea("", Model, new { maxlength = max, style = "width: " + (width) + "px; height: 60px;", @class = required ? "obrigatorio textarea" : "textarea" })
    }
    else
    {
    @Html.TextBox("", Model, new { maxlength = max, style = "width: " + width + "px;", @class = required ? "obrigatorio" : "" })     
    }
}
